package com.example.ui.share;

import java.util.List;

import com.example.huashangapp.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class ChineseMerchantInterviewActivity extends Activity {
	
	private Button titleLeftBtn,titleRightBtn;
	private TextView titleText;
	private ListView listview;
	private String[] strText = {"企业运营","金融投资","财税筹划","人力资源","市场营销","物流生产","领导艺术"};
	private int[] imgArr = {R.drawable.ic_launcher,R.drawable.nan2,R.drawable.face_0,
			R.drawable.picture,R.drawable.search_bg,R.drawable.nomale,
			R.drawable.ar_icon};
	private Intent myIntent;
	private TextView getIntentText;
	private String strTitle ;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.item01);
		myIntent=getIntent();
		strTitle = myIntent.getStringExtra("str");
		init();
	}

	private void init() {
		titleLeftBtn = (Button)findViewById(R.id.layout_title_left_btn);
		titleRightBtn= (Button)findViewById(R.id.layout_title_right_btn);
		titleText=(TextView)findViewById(R.id.layout_title_middle_text);
		getIntentText=(TextView)findViewById(R.id.item01_text_title);
		listview = (ListView)findViewById(R.id.item01_listview);
		titleLeftBtn.setText("返回");
		titleText.setText("选课中心");
		titleRightBtn.setText("我正在听");
		getIntentText.setText(strTitle==null?"这里显示的是上一个页面中Intent传递过来的值":"Intent传过来的是：\n"+strTitle.toString());
		titleLeftBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		
		listview.setAdapter(new MyListViewAdapter(this));
		listview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				
			}
		});
	}
	
	

	class MyListViewAdapter extends BaseAdapter{
		private LayoutInflater inflater;
		private List<String> items;
		public MyListViewAdapter(Context mContext){
			inflater = LayoutInflater.from(mContext);
//			list = items;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return strText.length;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			Holder holder = null;
			if(convertView == null){
				convertView = inflater.inflate(R.layout.item01_listview_item, null);
				holder = new Holder();
            	holder.img = (ImageView)convertView.findViewById(R.id.item01_list_img);
				holder.textTitle = (TextView) convertView.findViewById(R.id.item01_list_text_title);
				holder.textNum = (TextView) convertView.findViewById(R.id.item01_list_text_num);
            	convertView.setTag(holder);
            } else {
                holder = (Holder) convertView.getTag();
            }
			
			holder.img.setBackgroundResource(imgArr[position]);
			holder.textTitle.setText(strText[position]);
			holder.textNum.setText("( 147个课程,41位讲师 )");
			return convertView;
		}
		
		class Holder{
        	ImageView img;
        	TextView textTitle;
        	TextView textNum;
        }
		
		
	}
	
	

}
